﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KendoMvcUI.Core;
using KendoMvcUI.Common;
using System.Web.Mvc;

namespace KendoMvcUI.UI
{
    public class TabStrip:KendoUIBase
    {
        public TabStrip(KendoUIControlSettings settings,ViewContext context,IViewDataContainer container)
            :base(settings,context,container)
        { }
    }
    public class TabStripSettings : KendoUIControlSettings
    {
        public TabStripSettings()
            : base("kendoTabStrip")
        { }
        [PropertySetting(IsIngoreForJavaScript=true)]
        public Action<AnimationSettings> Animation { get; set; }
        public bool? Collapsible { get; set; }
        /// <summary>
        /// Sets an array with the URLs from which the tabs content to be loaded from. 
        /// If only specific tabs should be loaded via Ajax, 
        /// then you should set the URLs to the corresponding positions in the array and set the other elements to null.
        /// </summary>
        [PropertySetting(IsIngoreForJavaScript = true)]
        public Action<List<string>> ContentUrls { get; set; }
        /// <summary>
        /// Sets the field of the data item that provides the text content of the tab content element.
        /// </summary>
        public string DataContentField { get; set; }
        /// <summary>
        /// Sets the field of the data item that provides the URL for the Ajax loaded tab content.
        /// </summary>
        public string DataContentUrlField { get; set; }
        /// <summary>
        /// Sets the field of the data item that provides the image URL of the tab.
        /// </summary>
        public string DataImageUrlField { get; set; }
        /// <summary>
        /// Sets the field of the data item that provides the CSS class of the tab.
        /// </summary>
        public string DataSpriteCssClass { get; set; }
        /// <summary>
        /// Sets the field of the data item that provides the text name of the tab.
        /// </summary>
        public string DataTextField { get; set; }
        /// <summary>
        /// Sets the field of the data item that provides the link URL for the tab.
        /// </summary>
        public string DataUrlField { get; set; }
        /// <summary>
        /// Specifies whether the TabStrip should be keyboard navigatable.
        /// </summary>
        public string Navigatable { get; set; }
        #region 事件
        public string On_Activate { get; set; }
        public string On_ContentLoad { get; set; }
        public string On_Error { get; set; }
        public string On_Select { get; set; }
        public string On_Show { get; set; }
        #endregion
        public override string ToJsSettings()
        {
            string jsScript = base.ToJsSettings();
            if (!jsScript.EndsWith(","))
                jsScript += ",";
            if(Animation!=null)
            {
                AnimationSettings animation = new AnimationSettings();
                Animation(animation);
                jsScript += animation.ToString() + ",";
            }
            if(ContentUrls!=null)
            {
                List<string> contentUrls = new List<string>();
                ContentUrls(contentUrls);
                string urls = "";
                foreach (var contentUrl in contentUrls)
                {
                    urls += string.Format("'{0}'", contentUrl) + ",";
                }
                jsScript += string.Format("[{0}]", urls.EndsWith(","));
            }
            
            return jsScript.TrimEnd(',');
        }
    }
}
